<?php
date_default_timezone_set('Asia/Shanghai');//时区配置
$conn=mysql_connect("localhost","root","");
mysql_select_db("1touz", $conn);
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn);

set_time_limit(0);

for($i = 0; $i<100; $i++){
	
	$result_list = db_fetch_arrays("select * from ych_account_log_$i",$conn);
	if($result_list){
		foreach ($result_list as $k=>$v){
			//$id = 100000000+$v['id']+1000000*($i);
			$id = 100000000+($k+1)+1000000*($i);
			$upsql = "update ych_account_log_$i  set id=$id where id=".$v['id'];
			mysql_query($upsql, $conn);
		}
	}
	
	
	$result1 = db_fetch_array("select max(id) as maxid from ych_account_log_$i",$conn);
	
	if($result1['maxid']){
		$auto = $result1['maxid']+1;
	}else{
		$auto = 100000000+$i*1000000;
	}
	
	$sql = "ALTER TABLE ych_account_log_$i auto_increment=$auto";
	mysql_query($sql, $conn);
}

$start = strtotime(date('Y-m-d 00:00:00'));
mysql_query("delete from ych_account_log where add_time < $start", $conn);

for($i = 0; $i < 100; $i++){
	$sql = "INSERT INTO ych_account_log SELECT * from ych_account_log_$i where add_time<$start";
	mysql_query($sql, $conn);
}

echo 'OK';

function db_fetch_arrays($sql, $conn) 	{
	$result = mysql_query($sql, $conn);
	$i = 0;
	$_res = array();
	while($res = mysql_fetch_array($result,MYSQL_ASSOC)) {
		foreach ($res as $key => $value){
			$_res[$i][$key] = $value;//直接转义
		}
		$i++;
	}
	return $_res;
}

function db_fetch_array($sql,$conn) {
		$result = mysql_query($sql, $conn);
		$res = mysql_fetch_array($result,MYSQL_ASSOC);
		$_res = "";
		if (is_array($res)){
			foreach ($res as $key => $value){
				$_res[$key] =$value;
			}
		}
		$query = $_res;
		return $query;
}